// logs.ts
// const util = require('../../utils/util.js')
// import http from '../../utils/http';

Page({
    data: {
        inputValue: '',
        logs: [],
    },
    bindKeyInput(e: any) {
        this.setData({
            inputValue: e.detail.value
        })
    },
    onLoad(options) {
        this.setData({
            inputValue: options.search
        })
        this.httpSearch(options.search);
        // console.log(axios)
    },
    async httpSearch(value: any) {
        wx.showLoading({
            title: 'Search...',
        })
        try {
            const res = await wx.cloud.callFunction({
                name: 'search',
                data: {
                    q: value
                },
            })
            //@ts-ignore
            const dbList = res.result.data || [];
            console.log('云函数查询结果', res);

            // const param = {
            //     st: 'web',
            //     q: value,
            //     types: 'web'
            // };
            // const header = {
            //     "Referer": "https://www.searchencrypt.com/",
            //     "Referrer-Policy": "strict-origin-when-cross-origin",
            //     'Content-Type': 'application/json' // 设置请求头中的Content-Type
            // };
            // const response = await http.get('api/search', param, { header });
            // console.log('接口', response.data)
            // const interfaceList = response.data.Results.map((item: any) => {
            //     return {
            //         content: item.Content,
            //         link: item.ClickUrl,
            //         title: item.Title
            //     }
            // }) || [];
            // console.log('接口查询结果', interfaceList)

            // const url = 'https://spapi.searchencrypt.com/api/search'; // 要代理的外部接口URL
            // const headers = {
            //     "Referer": "https://www.searchencrypt.com/",
            //     "Referrer-Policy": "strict-origin-when-cross-origin",
            //     'Content-Type': 'application/json' // 设置请求头中的Content-Type
            // };
            // const param = {
            //     st: 'web',
            //     q: value,
            //     types: 'web'
            // }; // 请求体中的数据
            // const response = await axios.get(url, {
            //     params: param,
            //     headers
            // }); // 发送POST请求
            // const interfaceList = response.data.Results.map(item => {
            //     return {
            //         content: item.Content,
            //         link: item.ClickUrl,
            //         title: item.Title
            //     }
            // }) || [];
            // console.log('接口查询结果', interfaceList)

            this.setData({
                logs: dbList
            })
        } catch (err) {
            console.log(err)
        }
        wx.hideLoading()
    },
    search() {
        this.httpSearch(this.data.inputValue);
    },
    jump(e: any) {
        const { index } = e.currentTarget.dataset;
        const item = this.data.logs[index]

    }
})
